package flc.ast.adapter;


import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.PdfBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class PdfAdapter extends StkProviderMultiAdapter<PdfBean> {

    public PdfAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new PdfProvider());
    }

    private class PdfProvider extends BaseItemProvider<PdfBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_pdf;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, PdfBean bean) {
            baseViewHolder.setText(R.id.tvPdfItemName, FileUtils.getFileName(bean.getPath()));
            baseViewHolder.setText(R.id.tvPdfItemDate, TimeUtils.millis2String(FileUtils.getFileLastModified(bean.getPath()), "yyyy年MM月dd日"));
            baseViewHolder.setText(R.id.tvPdfItemSize, ConvertUtils.byte2FitMemorySize(FileUtils.getFileLength(bean.getPath()), 1));
            if (bean.isSelected()) {
                baseViewHolder.getView(R.id.ivPdfItemSel).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivPdfItemSel).setVisibility(View.INVISIBLE);
            }
        }
    }

}
